<?php
require_once( 'need.inc.php' );
$user_id = Login::NeedLogin();

/* set */
$pageSize = 20;
$pageNo = 1;
/* end set */

$table = 'district';

/*
$p_ids = DB::LimitQuery( $table, array(
			'condition' => array( 'p_id' => 2, ),
			'order' => 'ORDER BY id ASC',
			));

$p_id = Utility::getColumn( $p_ids, 'id', false );
$town_name = Utility::getColumn( $p_ids, 'name', false );
$town_list = array_combine( $p_id, $town_name );
*/
$action = isset($_GET['action']) ? $_GET['action'] : null;

if ( $action == 'ajax' )
{
}
else
{
	$p_id = 2;
	extract( $_GET, EXTR_IF_EXISTS );

	$condition = null;
	if ( $p_id )
		$condition .= ($condition==null ? '' : " AND " ) . "`p_id`='$p_id'";
	$sql = "SELECT COUNT(1) AS count FROM `$table` " . (($condition) ? "WHERE $condition" : "");

	$r = DB::GetQueryResult($sql, true);
	$count = abs(intval($r['count']));

	$pageNo = isset($_GET['pagenum'])?$_GET['pagenum']:1;
	$offset = ($pageNo-1) * $pageSize;
	
	$lists = DB::LimitQuery( $table, array(
		'condition' => $condition, 
		'size' => $pageSize, 
		'offset' => $offset,
	));
	$pager = new Pager(array(
				'rowCount' => $count,
				'pageSize' => $pageSize,
				));
	Template::Assign( $_GET );

	Template::Display( 'district', array(
				'lists' => $lists,
				'pager' => $pager->paginate(),
				'table' => $table,
			/*	
				'town_list' => $town_list,
				'p_id' => $p_id,
			*/
				));
}
?>
